package com.sgb.kjwl.viewmodel.home;

import android.text.TextUtils;

import androidx.databinding.ObservableField;

import com.google.gson.reflect.TypeToken;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.packers.LaborWorkMomentDetailEntity;
import com.sgb.kjwl.model.entity.packers.LabourServiceAndEmploymentEntity;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.BiddingEntity;
import com.sgb.kjwl.model.entity.EmploymentEntity;
import com.sgb.kjwl.model.entity.FindJobEntity;
import com.sgb.kjwl.model.entity.FindPackersEntity;
import com.sgb.kjwl.model.entity.FindPeopleEntity;
import com.sgb.link.entity.PickFilterEntity;
import com.swgk.core.base.model.entity.H5ReEntity;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.TeamPriceItemEntity;
import com.sgb.kjwl.model.entity.TeamPriceListRequestEntity;
import com.sgb.kjwl.model.entity.packers.EngineeringCompanyEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.WebViewX5HostActivity;
import com.swgk.core.mmkvutil.CacheMarker;
import com.sgb.kjwl.view.ui.fragment.home.EngineeringTeamJobHuntingFragment;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.mmkvutil.MkvUtils;
import com.swgk.core.mmkvutil.DatalUtils;
import com.swgk.core.util.MLog;
import com.swgk.core.util.MToast;
import com.swgk.core.util.SharedPreferenceUtil;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class EngineeringTeamJobHuntingModel extends BaseViewModel {
    public HomeRepertory repertory;
    private EngineeringTeamJobHuntingFragment fragment;

    private Map<String, Object> map;
    //页数下标
    public int mPageIndex;
    //每页大小
    public int mPageSize = 3;
    public ObservableField<TeamPriceListRequestEntity> quotedPriceJson = new ObservableField<>(new TeamPriceListRequestEntity());
    private boolean isCache;
    private Type constructionTeamtType;

    public EngineeringTeamJobHuntingModel(EngineeringTeamJobHuntingFragment fragment, HomeRepertory repertory) {
        this.fragment = fragment;
        this.repertory = repertory;
        mPageIndex = 0;
    }

    /**
     * -------------------------------------H5详情-----------------------------------------------
     */
    public void getH5Url(String id, String type) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting(type).enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    //拼接路径
                    String url = data.getData().getUrl() + "?no=" + id + "&isdele=0";
                    //跳转到H5界面
                    WebViewX5HostActivity.start(fragment.getActivity(), url);
                } else {
                    //吐司失败信息
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

    /**
     * -------------------------------------劳务分包 H5详情-----------------------------------------------
     */
    public void getUrlSetting(String id) {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPickAPI().getUrlSetting("competitivePurchase").enqueue(new ICallBack<BaseEntity<H5ReEntity>>() {
            @Override
            public void onSuccess(BaseEntity<H5ReEntity> data) {
                if (data == null || data.getState() == null) {
                    return;
                }

                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    String url = data.getData().getUrl() + "?id=" + id;
                    String lng = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "");
                    String lat = SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "");
                    url = url + "&lng=" + lng + "&lat=" + lat;
                    MLog.d("api", "H5跳转链接  " + url);
                    WebViewX5HostActivity.start(fragment.getActivity(), url, id);
                } else {
                    MToast.showToast(fragment.getActivity(), data.getMsg());
                }
            }
        });
    }

//    /**
//     * -------------------------------------施工工队-----------------------------------------------
//     */
//    public void getEngineeringList(String firstCategoryNo, boolean isLoadMore, int position, int mItemType) {
//        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
//        mPageSize = 3;
//        map = new HashMap<>();
////        map.put("areacode", repertory.getAreaCode());
//        map.put("limit", mPageSize);
//        map.put("page", mPageIndex);
//        if (!"".equals(firstCategoryNo) && firstCategoryNo != null)
//            map.put("firstCategoryNo", firstCategoryNo);
//        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
//            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
//        }
//        Type type = new TypeToken<List<FindPackersEntity>>() {
//        }.getType();
//        boolean isCache = getCacheData(isLoadMore, mItemType, type,mPageIndex);
//        APIManager.getInstance().getPackerAPI().findTeam(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<FindPackersEntity>>>>() {
//            @Override
//            public void onSuccess(BaseEntity<ListResponse<List<FindPackersEntity>>> data) {
//                if (data == null || data.getState() == null)
//                    return;
//                setCacheData(data.getData().getList(), isLoadMore, mItemType,mPageIndex,isCache);
//            }
//        });
//    }

    // -------------------------------- 工队工程-工程分类 --------------------------------

    public void getCategoryType(int mItemType) {
        //数组的解析,生成type类型的对象
        Type type = new TypeToken<List<PickSelectEntity>>() {
        }.getType();
        //获取本地缓存，显示数据
        isCache = getCacheData(false, CacheMarker.CacheTeamServeType + mItemType, type, true, 1);
        if (isCache && !fragment.getIsRefresh()) {
            return;
        }
        APIManager.getInstance().getPackerAPI().getCategoryListTree(0).
                enqueue(new Callback<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Response<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>> data = response.body().getData();
                            List<PickSelectEntity> list = new ArrayList<>();
                            for (PickFilterEntity filterEntity : data) {
                                list.add(new PickSelectEntity(filterEntity.getNo(), filterEntity.getName()));
                            }
                            setCacheData(list, false, CacheMarker.CacheTeamServeType + mItemType, true, 1, isCache);
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    // -------------------------------- 工程公司-工程分类 --------------------------------

    public void getCompanyCategoryType() {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().getCategoryListTree(0).
                enqueue(new Callback<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Response<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>> data = response.body().getData();
                            List<PickSelectEntity> list = new ArrayList<>();
                            for (PickFilterEntity filterEntity : data) {
                                list.add(new PickSelectEntity(filterEntity.getNo(), filterEntity.getName()));
                            }
                            fragment.setTypeDatas(list);
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    // -------------------------------- 服务团队-联动工种 --------------------------------

    public void getLinkAgeWorkType() {
        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中", 0, true, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().getLinkAgeWorkType1().
                enqueue(new Callback<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>>() {
                    @Override
                    public void onResponse(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Response<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> response) {
                        DialogHelper.dismissProgressDialog();
                        if (response.body() == null || response.body().getState() == null) {
                            return;
                        }
                        if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                            List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>> data = response.body().getData();
                            List<PickSelectEntity> list = new ArrayList<>();
                            for (PickFilterEntity filterEntity : data) {
                                list.add(new PickSelectEntity(filterEntity.getNo(), filterEntity.getName()));
                            }
                            fragment.setTypeDatas(list);
                        }
                    }

                    @Override
                    public void onFailure(Call<BaseEntity<List<PickFilterEntity<List<PickFilterEntity<List<PickFilterEntity>>>>>>> call, Throwable t) {
                        DialogHelper.dismissProgressDialog();
                    }
                });
    }

    /**
     * -------------------------------------工程分类 -----------------------------------------------
     */
    public void getEngineeringType(int mItemType) {
        //数组的解析,生成type类型的对象
        Type type = new TypeToken<List<PickSelectEntity>>() {
        }.getType();
        //获取本地缓存，显示数据
        isCache = getCacheData(false, CacheMarker.CacheTeamServeType + mItemType, type, true, 1);
        APIManager.getInstance().getPackerAPI().getProTypeList(repertory.getAreaCode()).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    //保存最新数据
                    setCacheData(data.getData(), false, CacheMarker.CacheTeamServeType + mItemType, true, 1, isCache);
                }
            }
        });
    }

    /**
     * ------------------------------------------灵活用工的工程分类 -----------------------------------------------
     */

    public void getProTypeList(int mItemType) {
        //数组的解析,生成type类型的对象
        Type type = new TypeToken<List<PickSelectEntity>>() {
        }.getType();
        //获取本地缓存，显示数据
        isCache = getCacheData(false, CacheMarker.CacheTeamServeType + mItemType, type, true, 1);
        APIManager.getInstance().getPackerAPI().getfindJobFirstCategory(repertory.getAreaCode()).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    //保存最新数据
                    setCacheData(data.getData(), false, CacheMarker.CacheTeamServeType + mItemType, true, 1, isCache);
                }
            }
        });
    }

    /**
     * -------------------------------------找工程/劳务分包 -----------------------------------------------
     */
    public void getBiddingList(String no, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 3;
        map = new HashMap<>();
        map.put("areacode", "");
        map.put("city", "");
        map.put("limit", 3);
        map.put("name", "");
        map.put("page", mPageIndex);
        map.put("state", "");
        map.put("type", "2");
        map.put("sortMethod", 1);
        map.put("goodsType", no);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if (mPageIndex == 1 && position == 0 && !isRefresh && TextUtils.isEmpty(no)){
            //数组的解析,生成type类型的对象
            Type type = new TypeToken<List<FindJobEntity>>() {
            }.getType();
            //获取本地缓存，显示数据
            //获取本地缓存，显示数据
            isCache = getCacheData(isLoadMore, CacheMarker.CacheTeamServeList + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getPickAPI().getBiddingList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<BiddingEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<BiddingEntity>>> data) {
                DialogHelper.dismissProgressDialog();
                if (data == null || data.getState() == null) {
                    return;
                }
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if (data.getData() != null) {
                        if (mPageIndex == 1 && position == 0 && TextUtils.isEmpty(no)) {
                            //保存最新数据
                            setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                        } else {
                            fragment.showList(data.getData().getList(), isLoadMore);
                        }
                    }
                }
            }
        });
    }

//    public void getJobType() {
//        DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
//        APIManager.getInstance().getLookingforAJobAPI().getfindJobFirstCategory(repertory.getAreaCode()).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
//            @Override
//            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
//                if (data == null || data.getState() == null) {
//                    return;
//                }
//                if (data.getState().equals(APIManager.RESPONSE_OK)) {
//                    fragment.showTeamTypeData(data.getData());
//                }
//            }
//        });
//    }

    /**
     * -------------------------------------找工人 -----------------------------------------------
     */

    public void getWorkList(String workType, String industryNo, boolean isLoadMore, int position, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        mPageSize = 3;
        map = new HashMap<>();
//        map.put("provinceNo", repertory.getAreaCode());
        //设置每页大小
        map.put("limit", mPageSize);
        //设置页数下标
        map.put("page", mPageIndex);
        map.put("type", -1);
        //当不为空时，将workType存入map
        if (!TextUtils.isEmpty(workType)) {
            map.put("workType", workType);
        }
        map.put("industryNo", industryNo);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        //数组的解析,生成type类型的对象
        Type type = new TypeToken<List<FindPeopleEntity>>() {
        }.getType();
        //获取本地缓存，显示数据
        if (!isRefresh) {
            //获取本地缓存，显示数据
            isCache = getCacheData(isLoadMore, CacheMarker.CacheTeamServeList + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getPackerAPI().getPackerPeopleList(map).enqueue(new ICallBack<BaseEntity<List<FindPeopleEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<FindPeopleEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    //保存最新数据
                    setCacheData(data.getData(), isLoadMore, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                }
            }
        });
    }

    /**
     * 是否有缓存
     */
    public <T> boolean getCacheData(boolean isLoadMore, String mType, Type type, boolean isType, int page) {
        if (fragment.getPosition() == 0 && page == 1) {
            //获取到object的数据
            Object object = DatalUtils.getInstance().getData(MkvUtils.CacheModular, mType, type);
            //当不为空时
            if (object != null) {
                //强转
                List<PickSelectEntity> list = (List<PickSelectEntity>) object;
                //根据参数判断数据是分类数据还是数据列表
                if (isType) {
                    fragment.setTypeDatas(list);
                } else {
                    fragment.showList(list, isLoadMore);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 是否更新缓存
     */
    public <T> void setCacheData(List<T> dataList, boolean isLoadMore, String mType, boolean isType, int page, boolean isCache) {
        //判断是否是第一个fragment并且是第一页时
        if (fragment.getPosition() == 0 && page == 1) {
            ////获取本地数据的哈希值
            String cacheMateialistlHash = DatalUtils.getHashData(MkvUtils.CacheModular, mType);
            //获取从网络请求下来的数据的哈希值
            String mHashNet = DatalUtils.getInstance().strToHashKey(dataList);
            //判断双方的哈希值是否一样
            if (!cacheMateialistlHash.equals(mHashNet) || isCache == false) {
                DatalUtils.getInstance().putData(MkvUtils.CacheModular, mType, dataList);
                if (isType) {
                    fragment.setTypeDatas((List<PickSelectEntity>) dataList);
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
            } else {
                if (isType) {
                } else {
                    fragment.showList(dataList, isLoadMore);
                }
            }
        }
        //当不符合条件时，直接根据类型条件各自显示
        else {
            if (isType) {
                fragment.setTypeDatas((List<PickSelectEntity>) dataList);
            } else {
                fragment.showList(dataList, isLoadMore);
            }
        }
    }

    /**
     * ----------------------------------施工队、班组、承包商等三个列表的共同请求-----------------------------------------
     */
    public void getConstructionTeamList(String teamType, String categoryNo, int position, boolean b, int mItemType, boolean isRefresh) {
        map = new HashMap();
        mPageIndex = b ? mPageIndex + 1 : 1;
        //设置每页大小
        map.put("limit", mPageSize);
        //设置页数下标
        map.put("page", mPageIndex);
        //设置工队类型 0  施工队  1  班组   2 工程公司
        map.put("teamType", teamType);
        //工程类别
        map.put("categoryNo", categoryNo);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        //数组的解析,生成type类型的对象
        if (constructionTeamtType == null) {
            constructionTeamtType = new TypeToken<List<FindPackersEntity>>() {
            }.getType();
        }
        if (!isRefresh) {
            //获取本地缓存，显示数据
            isCache = getCacheData(b, CacheMarker.CacheTeamServeList + mItemType, constructionTeamtType, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getPackerAPI().getEngineeringList(map).enqueue(new ICallBack<BaseEntity<ListResponse<List<EngineeringCompanyEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<EngineeringCompanyEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    //保存最新数据
                    setCacheData(data.getData().getList(), b, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                }
            }
        });
    }

    public void getTeamList(String categoryNo, String firstCategoryNo, int position, boolean isLoadMore, int mItemType, boolean isRefresh) {
        map = new HashMap();
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        //设置每页大小
        map.put("limit", mPageSize);
        //设置页数下标
        map.put("page", mPageIndex);
        //设置分类编号
        map.put("teamType", categoryNo);
        //工程类别
        map.put("firstCategoryNo", firstCategoryNo);
        //第一模块的第一页数据加载时不显示loading
        if (!(mPageIndex == 1 && position == 0 && TextUtils.isEmpty(firstCategoryNo))) {
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        //数组的解析,生成type类型的对象
        if ("".equals(firstCategoryNo) && mPageIndex == 1 && position == 0 && !isRefresh) {
            Type type = new TypeToken<List<FindPackersEntity>>() {
            }.getType();
            //获取本地缓存，显示数据
            isCache = getCacheData(isLoadMore, CacheMarker.CacheTeamServeList + mItemType, type, false, mPageIndex);
            if (isCache) {
                return;
            }
        }
        APIManager.getInstance().getPackerAPI().getTeamList(map).enqueue(new ICallBack<BaseEntity<List<FindPackersEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<FindPackersEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if ("".equals(firstCategoryNo) && mPageIndex == 1 && position == 0) {
                        //保存最新数据
                        setCacheData(data.getData(), isLoadMore, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                    }else{
                        fragment.showList(data.getData(), isLoadMore);
                    }
                }
            }
        });
    }

    /**
     * ------------------------------------------招工用工列表 -----------------------------------------------
     **/

    public void getEmploymentList(String categoryNo, int position, boolean isLoadMore, int mItemType, boolean isRefresh) {
        map = new HashMap();
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        //设置每页大小
        map.put("limit", mPageSize);
        //设置页数下标
        map.put("page", mPageIndex);
        //设置分类编号
        map.put("categoryNo", categoryNo);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        //数组的解析,生成type类型的对象
        if ("".equals(categoryNo)) {
            Type type = new TypeToken<List<EmploymentEntity>>() {
            }.getType();
            //获取本地缓存，显示数据
            if (!isRefresh) {
                //获取本地缓存，显示数据
                isCache = getCacheData(isLoadMore, CacheMarker.CacheTeamServeList + mItemType, type, false, mPageIndex);
                if (isCache) {
                    return;
                }
            }
        }
        APIManager.getInstance().getPackerAPI().getEmploymentList(map).enqueue(new ICallBack<BaseEntity<List<EmploymentEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<EmploymentEntity>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if ("".equals(categoryNo)) {
                        //保存最新数据
                        setCacheData(data.getData(), isLoadMore, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                    } else {
                        fragment.showList(data.getData(), isLoadMore);
                    }
                }
            }
        });
    }

    /**
     * ------------------------------------------工种报价列表 -----------------------------------------------
     **/

    public void getWorkQuotationList(String categoryNo, int position, boolean isLoadMore, int mItemType, boolean isRefresh) {
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        //设置页数下标
        quotedPriceJson.get().setPage(mPageIndex);
        //设置每页大小
        quotedPriceJson.get().setLimit(mPageSize);
        //设置分类编号
        quotedPriceJson.get().setFirstCategoryNo(categoryNo);
        if (!(mPageIndex == 1 && position == 0)) {//第一模块的第一页数据加载时不显示loading
            DialogHelper.showProgressDialog(fragment.getActivity(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        }
        if ("".equals(categoryNo)) {
            //数组的解析,生成type类型的对象
            Type type = new TypeToken<List<TeamPriceItemEntity>>() {
            }.getType();
            //获取本地缓存，显示数据
            if (!isRefresh) {
                //获取本地缓存，显示数据
                isCache = getCacheData(isLoadMore, CacheMarker.CacheTeamServeList + mItemType, type, false, mPageIndex);
                if (isCache) {
                    return;
                }
            }
        }
        //网络请求
        APIManager.getInstance().getTeamPriceAPI().findPriceList(quotedPriceJson.get()).enqueue(new ICallBack<BaseEntity<ListResponse<List<TeamPriceItemEntity>>>>() {
            @Override
            public void onSuccess(BaseEntity<ListResponse<List<TeamPriceItemEntity>>> data) {
                if (data == null || data.getState() == null) {
                    return;
                }
                //判断网络请求是否正常
                if (data.getState().equals(APIManager.RESPONSE_OK)) {
                    if ("".equals(categoryNo)) {
                        //保存最新数据
                        setCacheData(data.getData().getList(), isLoadMore, CacheMarker.CacheTeamServeList + mItemType, false, mPageIndex, isCache);
                    } else {
                        fragment.showList(data.getData().getList(), isLoadMore);
                    }
                }
            }
        });
    }

    //劳务分包
    public void getTenderGoodsCategoryAllList() {
        Map map = new HashMap();
        map.put("type", "2");
        DialogHelper.showProgressDialog(fragment.getContext(), null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getPackerAPI().getTenderGoodsCategoryList(map).enqueue(new ICallBack<BaseEntity<List<PickSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity>> data) {
                List<PickSelectEntity> list = data.getData();
                list.remove(0);
                fragment.setTypeDatas(list);
            }
        });
    }

    //劳务用工行业分类类别
    public void getLinkAgeType() {
        APIManager.getInstance().getPackerAPI().getLinkAgeWorkType().enqueue(new ICallBack<BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>>>() {
            @Override
            public void onSuccess(BaseEntity<List<PickSelectEntity<List<PickSelectEntity<List<PickSelectEntity>>>>>> data) {
                fragment.setTypeDatas(data.getData());
            }
        });
    }

    //劳务用工列表
    public void getLabourList(String industryNo, int position, boolean isLoadMore, int mItemType, boolean isRefresh) {
        map = new HashMap();
        mPageIndex = isLoadMore ? mPageIndex + 1 : 1;
        map.put("industryNo", industryNo);
        map.put("limit", mPageSize);
        map.put("page", mPageIndex);
       /* if ("Y".equals(isInit)) {
            map.put("isInit", isInit);
        }*/
        APIManager.getInstance().getPackerAPI().getLabourList(map).enqueue(new ICallBack<BaseEntity<List<LabourServiceAndEmploymentEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<LabourServiceAndEmploymentEntity>> data) {
                fragment.showList(data.getData(), isLoadMore);
            }
        });
    }

    //劳务用工详情
    public void getLaborWorkDetail(LabourServiceAndEmploymentEntity entity) {
        APIManager.getInstance().getPackerAPI().getLaborWorkDetail(entity.getNo()).enqueue(new ICallBack<BaseEntity<LaborWorkMomentDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<LaborWorkMomentDetailEntity> data) {
                fragment.setLaborWorkDetail(data.getData(), entity);
            }
        });
    }
}
